package text
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	
	public class ScaleAnchor extends Sprite
	{
		private var _direction:int;
		private var _position:Rectangle;
		
		public function set direction($value:int):void
		{
			_direction = $value;
		}
		
		public function get direction():int
		{
			return _direction;
		}
									 
		
		public function ScaleAnchor()
		{
			super();
			init();
		}
		
		private function init():void
		{
			var shape:Shape = new Shape;
			shape.graphics.beginFill(0xFFFFFF,1);
			shape.graphics.lineStyle(1, 0xFF6600);
			shape.graphics.drawRect(-3,-3,6,6);
			shape.graphics.endFill();
			addChild(shape);
		}
		
		public function set position($value:Rectangle):void
		{
			_position = $value;
		}
		
		public function setPosition($value:Rectangle):void
		{
			switch(_direction)
			{
				case 0:
					this.x = $value.x;
					this.y = $value.y;
					break;
				case 1:
					this.x = $value.width + $value.x;
					this.y = $value.y;
					break;
				case 2:
					this.x = $value.width + $value.x;
					this.y = $value.height + $value.y;
					break;
				case 3:
					this.x = $value.x;
					this.y = $value.height + $value.y;
					break;
			}
		}
		
		public function get position():Rectangle
		{
			var rst:Rectangle;
			switch(_direction)
			{
				case 0:
					rst = new Rectangle(this.x, this.y, _position.width - this.x, _position.height - this.y);
					break;
				case 1:
					rst = new Rectangle(0, this.y, this.x, _position.height - this.y);
					break;
				case 2:
					rst = new Rectangle(0, 0, this.x, this.y);
					break;
				case 3:
					rst = new Rectangle(this.x, 0, _position.width - this.x, this.y);
					break;
			}
			return rst;
		}
		
	}
}